﻿///////////////////////////////////////////////////////////////////////////////////////////////
// System.Text.Parsing - © 2011 Sebastien Pellizzari
// Released under the MIT License (http://www.opensource.org/licenses/mit-license.php)
///////////////////////////////////////////////////////////////////////////////////////////////

namespace System.Text.Parsing
{
    /// <summary>Represents the source file and text range of a chunk of grammar text.</summary>
    public struct GrammarSourceRange
    {
        private readonly string _sourceIdentity;
        private readonly TextRange _range;

        //-----------------------------------------------------------------------
        //     Properties
        //-----------------------------------------------------------------------

        /// <summary>Gets whether the source range is equal to <see cref="GrammarSourceRange.Unknown"/>.</summary>
        public bool IsUnknown { get { return _sourceIdentity == null; } }
        /// <summary>Gets a string that identifies the source of the grammar, such as a path to a text file.</summary>
        public string SourceIdentity { get { return _sourceIdentity; } }
        /// <summary>Gets the range of the text in the source.</summary>
        public TextRange Range { get { return _range; } }

        /// <summary>A <see cref="GrammarSourceRange"/> that represents an unknown source range.</summary>
        public static readonly GrammarSourceRange Unknown = new GrammarSourceRange(null);

        //-----------------------------------------------------------------------
        //     Constructors
        //-----------------------------------------------------------------------

        /// <summary>Initializes an instance of the <see cref="GrammarSourceRange"/> class.</summary>
        /// <param name="sourceIdentity">The source identity.</param>
        public GrammarSourceRange(string sourceIdentity)
        {
            _sourceIdentity = sourceIdentity;
            _range = TextRange.Unknown;
        }

        /// <summary>Initializes an instance of the <see cref="GrammarSourceRange"/> class.</summary>
        /// <param name="sourceIdentity">The source identity.</param>
        /// <param name="range">The source text range.</param>
        public GrammarSourceRange(string sourceIdentity, TextRange range)
        {
            _sourceIdentity = sourceIdentity;
            _range = range;
        }
    }
}
